<template>
  <div class="history-container">
    <van-cell class="title">
      <div slot="title">历史记录</div>
      <div slot="default">
        <span v-if="isDel" @click="delAll">全部删除</span>
        &nbsp; &nbsp;
        <span @click="isDel=!isDel">{{ isDel ? '完成' : '删除' }}</span>
      </div>
    </van-cell>
    <van-cell v-for="(item, index) in historyList" :key="index">
      <span slot="title">{{ item }}</span>
      <van-icon v-if="isDel" slot="right-icon" name="delete-o" @click="delOne(index)"></van-icon>
    </van-cell>
  </div>
</template>

<script>
import { getToken, setToken } from '@/utils/storage.js'
export default {
  name: 'HistorySearch',
  props: {
  },
  data() {
     return {
       historyList: [],
       isDel: false
     }
  },
  computed: {
    // historyList() {
    //   return getToken('HISTORY-LIST')
    // }
  },
  created() {
    this.getHistoryList()
  },
  methods: {
    getHistoryList() {
      this.historyList = getToken('HISTORY-LIST')
    },
    delAll() {
      setToken('HISTORY-LIST', [])
      this.isDel = false
      this.historyList = getToken('HISTORY-LIST')
    },
    delOne(index) {
      this.historyList.splice(this.historyList[index], 1)
      setToken('HISTORY-LIST', this.historyList)
      this.getHistoryList()
    }
  }
}
</script>

<style scope lang="less">
.history-container {
    .title {
      .van-cell__title {
      span {
        font-size: 32px;
      }
    }
    .van-cell {}
  }
}
</style>
